package dao

import "new/models"

func GetAllParts(PartsParam map[string]interface{}) (error, []models.Parts, int64) {
	var partsData []models.Parts
	page := PartsParam["page"].(int)
	pageSize := PartsParam["limit"].(int)
	searchName := PartsParam["searchName"].(string)
	var total int64
	err := db.Table("parts p").Select("p.pno, p.pname, p.unit_price, p.inventory, p.mininventory ").Where("p.name like ? ", searchName+"%").Order("p.pno ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&partsData).Error
	return err, partsData, total
}
func DelParts(pno int) error {
	err := db.Table("parts").Where("pno = ?", pno).Error
	return err
}
func UpdateParts(parts models.Parts) error {
	err := db.Table("parts").Select("column:unit_price","inventory","mininventory").Where("pno = ?", parts.PartsPno).Updates(&parts).Error
	return err
}
func AddParts(parts models.Parts) (error) {
	err := db.Table("parts").Select("pno", "pname", "unit_price","inventory", "mininventory").Create(&parts).Error
	return err
}
